#include "ShrinkCube.h"
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCubeSource.h>
#include <vtkDataSetMapper.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkShrinkFilter.h>

ShrinkCube::ShrinkCube(QWidget *parent)
    : QMainWindow(parent)
{
	vtkWidget = new QVTKOpenGLNativeWidget(this);
	this->resize(600, 400);
	this->setCentralWidget(vtkWidget);
	// Create a cube.
	vtkNew<vtkCubeSource> cubeSource;

	vtkNew<vtkShrinkFilter> shrink;
	shrink->SetInputConnection(cubeSource->GetOutputPort());
	shrink->SetShrinkFactor(.9);

	// Create a mapper and actor.
	vtkNew<vtkNamedColors> colors;

	vtkNew<vtkDataSetMapper> mapper;
	mapper->SetInputConnection(shrink->GetOutputPort());

	vtkNew<vtkProperty> back;
	back->SetColor(colors->GetColor3d("Tomato").GetData());

	vtkNew<vtkActor> actor;
	actor->SetMapper(mapper);
	actor->GetProperty()->EdgeVisibilityOn();
	actor->GetProperty()->SetColor(colors->GetColor3d("Banana").GetData());
	actor->SetBackfaceProperty(back);

	// Create a renderer, render window, and interactor
	vtkNew<vtkRenderer> renderer;

	// Add the actors to the scene
	renderer->AddActor(actor);
	renderer->SetBackground(colors->GetColor3d("Silver").GetData());

	renderer->ResetCamera();
	renderer->GetActiveCamera()->Azimuth(30);
	renderer->GetActiveCamera()->Elevation(30);
	renderer->ResetCameraClippingRange();

	vtkWidget->renderWindow()->AddRenderer(renderer);
	
}
